import { RegisterComponent } from '@feng3d/ecs';
import { Component3D } from 'feng3d-three';
import { CCDIKHelper, CCDIKSolver, IKS, SkinnedMesh } from '../thirdparty/three/imports';

export class CCDIKSolver3D
{
    _CCDIKSolver: CCDIKSolver;

    constructor(mesh: SkinnedMesh, iks: IKS[])
    {
        this._CCDIKSolver = new CCDIKSolver(mesh, iks);
    }

    update()
    {
        this._CCDIKSolver.update();
    }
}

declare module '@feng3d/ecs'
{
    interface ComponentMap { CCDIKHelper3D: CCDIKHelper3D; }
}

/**
 * 3D场景，包装`three`中`Scene`
 */
@RegisterComponent({ name: 'CCDIKHelper3D' })
export class CCDIKHelper3D extends Component3D
{
    _helper: CCDIKHelper;

    mesh: SkinnedMesh;
    iks?: IKS[];
    sphereSize?: number;

    init(): void
    {
        super.init();

        this._helper = new CCDIKHelper(this.mesh, this.iks, this.sphereSize);
        this.entity._group.add(this._helper);
    }

    destroy(): void
    {
        this.entity._group.remove(this._helper);
        this._helper = null;
    }
}
